package com.hedl.classroom.feignclient;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.hedl.classroom.config.MultipartSupportConfig;
import com.hedl.classroom.feignclient.impl.MediaServiceClientFallbackFactory;
import com.hedl.classroom.model.dto.UploadFileResultDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Big Watermelon
 * @description 远程调用媒资服务的接口
 * @date 2023/11/28/21:23
 * 使用fallback定义降级类是无法拿到熔断异常的
 * 使用fallbackFactory是可以拿到熔断异常信息的
 */
@Component
@FeignClient(name = "media-api",configuration = {MultipartSupportConfig.class},fallbackFactory = MediaServiceClientFallbackFactory.class)
public interface MediaServiceClient {

    /**
     * 有问题，无法满足降级，后续更改；修改成了使用openfeign结合sentinel使用，目前可以正常使用
     * @param filedata
     * @param folder
     * @param objectName
     * @return
     */
    @RequestMapping(value = "/media/upload/coursefile",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String upload(@RequestPart(value = "filedata",required = false) MultipartFile filedata,
                                      @RequestParam(value = "folder", required = false) String folder,
                                      @RequestParam(value = "objectName", required = false) String objectName);

}